package server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Connector implements Lifecycle{

    private String port;

    private Service service;

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public Service getService() {
        return service;
    }

    public void setService(Service service) {
        this.service = service;
    }

    @Override
    public void start() {
        new Thread(()->{
            try {
                ServerSocket serverSocket = new ServerSocket(Integer.valueOf(port));
                while(true) {
                    Socket socket = serverSocket.accept();
                    RequestProcessor requestProcessor = new RequestProcessor(socket,service);
                    //requestProcessor.start();
                    service.getThreadPoolExecutor().execute(requestProcessor);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }).start();


    }
}
